#include "prep.h"
#include "selectincludefile.h"
#include <wx/xrc/xmlres.h>
#include <wx/arrstr.h>
#include <sdk.h>

BEGIN_EVENT_TABLE( SelectIncludeFile, wxScrollingDialog )
  EVT_LISTBOX_DCLICK( XRCID( "ID_LBX_INCLUDE_FILES" ), SelectIncludeFile::OnOk )
  EVT_BUTTON( XRCID( "ID_BTN_OK" ), SelectIncludeFile::OnOk )
  EVT_BUTTON( XRCID( "ID_BTN_CANCEL" ), SelectIncludeFile::OnCancel )
END_EVENT_TABLE()

SelectIncludeFile::SelectIncludeFile( wxWindow* parent, M_Code_unused wxWindowID id ) {
  wxXmlResource* xml_res = wxXmlResource::Get();
  wxString resPath = ConfigManager::GetDataFolder() + _T( "/selectincludefile.xrc" );
  xml_res->Load( resPath );
  if( !xml_res->LoadObject( this, parent, _T( "SelectIncludeFile" ), _T( "wxScrollingDialog" ) ) ) {
    return;
  }
  LstIncludeFiles = XRCCTRL( *this, "ID_LBX_INCLUDE_FILES", wxListBox );
}

SelectIncludeFile::~SelectIncludeFile() {
}

void SelectIncludeFile::OnOk( M_Code_unused wxCommandEvent& event ) {
  int pos = LstIncludeFiles->GetSelection();
  if( pos != wxNOT_FOUND ) {
    m_SelectedIncludeFile = LstIncludeFiles->GetString( pos );
  } else {
    m_SelectedIncludeFile.Clear();
  }
  EndModal( wxID_OK );
}

void SelectIncludeFile::OnCancel( M_Code_unused wxCommandEvent& event ) {
  EndModal( wxID_CANCEL );
}

void SelectIncludeFile::AddListEntries( const wxArrayString& IncludeFiles ) {
  LstIncludeFiles->InsertItems( IncludeFiles, 0 );
  LstIncludeFiles->SetSelection( 0 );
}
